package ${groupId}.config.swagger;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

@Component
@Primary
public class SwaggerProvider implements SwaggerResourcesProvider{
	
	@Autowired
	private Environment env;

	@Override
	public List<SwaggerResource> get() {
		List<SwaggerResource> resources = new ArrayList<>();
		registerSwaggerService(resources);
		return resources;
	}

	private void registerSwaggerService(List<SwaggerResource> swaggerResources) {
		String groupName = "${artifactId}("+env.getActiveProfiles()[0]+"环境)";
		SwaggerResource resource = new SwaggerResource();
		resource.setName(groupName);
		resource.setLocation("/v3/api-docs?group=${artifactId}");
		resource.setSwaggerVersion("3.0");
		swaggerResources.add(resource);
	}
}
